package com.example.supernote.data.repository

import com.example.supernote.data.dao.FileEntityDao
import com.example.supernote.data.dao.TrashEntityDao
import com.example.supernote.data.entity.FileEntity
import com.example.supernote.data.entity.TrashEntity
import kotlinx.coroutines.flow.Flow

class OfflineFileEntityRepository(
    private val fileEntityDao: FileEntityDao,
    private val trashEntityDao: TrashEntityDao
) : FileEntityRepository {
    override suspend fun deleteFileEntityById(id: Int) {
        fileEntityDao.deleteById(id)
    }

    override suspend fun getFileEntityStream(id: Int): FileEntity {
        return fileEntityDao.getItem(id)
    }

    override suspend fun insertFileEntity(fileEntity: FileEntity) {
        fileEntityDao.insert(fileEntity)
    }

    override suspend fun updateFileEntity(fileEntity: FileEntity) {
        fileEntityDao.update(fileEntity)
    }

    override fun getAllFileEntitiesStream(): Flow<List<FileEntity>> {
        return fileEntityDao.getAllItems()
    }
    /**
     * Trash
     */
    override suspend fun deleteTrashEntityById(id: Int) {
        trashEntityDao.deleteById(id)
    }

    override suspend fun insertTrashEntity(trashEntity: TrashEntity) {
        trashEntityDao.insert(trashEntity)
    }

    override suspend fun getTrashEntityStream(id: Int): TrashEntity {
        return trashEntityDao.getItem(id)
    }

    override fun getAllTrashEntitiesStream(): Flow<List<TrashEntity>> {
        return trashEntityDao.getAllItems()
    }
}